﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;

namespace Meirimoney.Exchange.Website.Utilities
{
    public class Tools
    {
        /// <summary>
        /// MD5哈希加密
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string Md5Hash(string input)
        {
            MD5 md5Hasher = MD5.Create();
            byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
            StringBuilder sBuilder = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            return sBuilder.ToString();
        }


        /// <summary>
        /// 获取指定表示的时间戳
        /// </summary>
        /// <param name="time">指定的时间</param>
        /// <returns>返回秒数</returns>
        public static int ToUnixTime(DateTime time)
        {
            return (int)(time.ToUniversalTime() - (new DateTime(1970, 1, 1, 0, 0, 0, 0, 0))).TotalSeconds;
        }
    }
}